﻿<%@ Page Title="Admin" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Admin.aspx.cs" Inherits="RoomService.Account.Admin" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    
    <script type="text/javascript">

        var GetPersURl = "http://23.23.80.142/RoomServiceWCF/pers/5";
        var GetListingsURl = "http://23.23.80.142/RoomServiceWCF/listing";


        function createDynamicTable(tbody, rows, cols, filtered_listing) {
            var min = $('#min').val();
            var max = $('#max').val();
            var i;

            var Rate = new Array(filtered_listing.Length);
            var Title = new Array(filtered_listing.Length);
            var City = new Array(filtered_listing.Length);
            var State = new Array(filtered_listing.Length);
            var Street_address = new Array(filtered_listing.Length);

            for (i = 0; i < filtered_listing.length; i++) {

                Rate[i] = filtered_listing[i].listing_rate;
                Title[i] = filtered_listing[i].listing_title;
                City[i] = filtered_listing[i].Address.city;
                State[i] = filtered_listing[i].Address.state;
                Street_address[i] = filtered_listing[i].Address.street_address_1;

                //alert(Street_address[i]);
            }


            if (tbody == null || tbody.length < 1) return;
            for (var r = 1; r <= rows; r++) {

                var trow = $("<tr>");
                for (var c = 1; c <= cols; c++) {
                    //alert(Rate[r - 1]);
                    var cellRate = Rate[r - 1];
                    $("<td>")
                           .addClass("tableCell")
                          .text(cellRate)
                          .data("col", c)
                          .appendTo(trow);
                    //alert(Rate[r]);
                    var cellTitle = Title[r - 1]
                    //alert(addr);
                    $("<td>")
                           .addClass("tableCell")
                          .text(cellTitle)
                          .data("col", c)
                          .appendTo(trow);
                    var cellAddress = Street_address[r - 1]
                    //alert(addr);
                    $("<td>")
                           .addClass("tableCell")
                          .text(cellAddress)
                          .data("col", c)
                          .appendTo(trow);
                    var cellCity = City[r - 1]
                    //alert(addr);
                    $("<td>")
                           .addClass("tableCell")
                          .text(cellCity)
                          .data("col", c)
                          .appendTo(trow);
                    var cellState = State[r - 1]
                    //alert(addr);
                    $("<td>")
                           .addClass("tableCell")
                          .text(cellState)
                          .data("col", c)
                          .appendTo(trow);

                }
                trow.appendTo(tbody);
            }
        }

        function withinPriceRange(list_rate) {
            var min = $('#min').val();
            var max = $('#max').val();
            if (max < list_rate) {
                return false;
            }
            if (min > list_rate) {
                return false;
            }
            return true;
        }

        $(document).ready(function () {
            $.ajax({
                cache: false,
                type: "GET",
                async: false,
                dataType: "json",
                url: GetListingsURl,
                success: function (listing) {
                    //alert("success");
                },
                error: function (xhr) {
                    //alert(xhr.statusText);
                }
            });

            $("#get_listing").click(function () {

                $.ajax({
                    cache: false,
                    type: "GET",
                    async: false,
                    url: GetListingsURl,
                    contentType: "application/json",
                    dataType: "json",
                    success: function (listing) {

                        var array_size = listing.length;
                        var filtered_out_values = 0;
                        for (i = 0; i < array_size; i++) {
                            if ((listing[i].listing_rate != null) && (withinPriceRange(listing[i].listing_rate))) {
                                //listing[i] = null;
                                //alert(listing[i].Address.city);
                                filtered_out_values++;
                            }
                        }

                        //alert(filtered_out_values);
                        var filtered_listing = new Array(filtered_out_values);

                        //
                        for (i = 0; i < filtered_listing.length; i++) {
                            for (var j = 0; j < listing.length; j++) {
                                if ((listing[j].listing_rate != null) && (withinPriceRange(listing[j].listing_rate))) {
                                    filtered_listing[i] = listing[j];
                                    // sqft_array[i] = listing[j].
                                    listing[j] = 0;
                                    break;
                                }
                            }
                        }

                        //filtered_listing.Address = listing.Address;
                        createDynamicTable($("#tbl"), filtered_listing.length, 1, filtered_listing);

                    },
                    error: function (xhr) {
                        alert("On Click");
                    }
                });
            });
        });
</script>


    <section id="forms">
  <div class="page-header">
    <h1>Admin DashBoard</h1>
  </div>
  
  <form>
        
    <form>
        <fieldset class="form-horizontal well span8 offset4">
        <asp:Button id="get_listing">Users</button>
        <table class="table table-bordered table-striped" width="100" id="tbl" border="1">


        <tr>
         
 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataSourceID="SqlDataSource4"
            CssClass="table table-striped table-bordered table-condensed"
            >
            <Columns>
                <asp:BoundField DataField="UserId" HeaderText="User ID" 
                    SortExpression="column1" />
                <asp:BoundField DataField="username" HeaderText="Username" SortExpression="rent" />
            <asp:BoundField DataField="fname" HeaderText="First Name" SortExpression="rent" />
             <asp:BoundField DataField="lname" HeaderText="Last Name" SortExpression="rent" />
              <asp:BoundField DataField="phone" HeaderText="Phone Number" SortExpression="rent" />
               <asp:BoundField DataField="email" HeaderText="Email" SortExpression="rent" />

     
            </Columns>

          </asp:GridView>
 
        </fieldset>
    </form>
     
        <asp:SqlDataSource ID="SqlDataSource4" runat="server" 
            ConnectionString="<%$ ConnectionStrings:gsuhousingConnectionString %>" 
            SelectCommand="SELECT Members.[UserId], [username], [fname], [lname], [phone], [email] FROM [Members] INNER JOIN [Profile] ON Members.MemID = Profile.MemID"
            >
           
          
        </asp:SqlDataSource>

  <asp:Table ID = "table1" runat="server" class="table table-bordered table-striped" padding="300">
            
            </asp:Table>

   <asp:label id="lblMessage" runat="server" width="288px" font-bold="True" font-italic="True"
            font-size="Medium" forecolor="#C00000"></asp:label>
     
</form>
    
    </form>
</asp:Content>
